package com.kehao.leetcode.algorithm;

import org.junit.Test;

import java.util.HashMap;
//https://leetcode-cn.com/problems/two-sum/
public class Solution1 {
    @Test
    public void myTest(){
        int[] twoSum = twoSum(new int[]{3, 2, 4}, 6);
        System.out.println(twoSum[0]+"  "+twoSum[1]);
    }

    public int[] twoSum(int[] nums, int target) {
        HashMap map = new HashMap();
        for (int i = 0; i < nums.length; i++) {
            if(map.containsKey(target-nums[i])){
                return new int[]{(int) map.get(target-nums[i]),i};
            }
            map.put(nums[i],i);
        }
        return new int[]{0,0};
    }
}
